package com.hspedu.homework;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/11
 * @time 17:21
 */
public class Homework01 {
    public static void main(String[] args) {
        List<Employee> list = new ArrayList<>();
        list.add(new Employee("jack",10000,new MyDate(14,5,2002)));
        list.add(new Employee("bob",20000,new MyDate(14,6,2000)));
        list.add(new Employee("lucy",30000,new MyDate(14,7,2003)));

        Collections.sort(list, new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                int nameMinus = o1.getName().length() - o2.getName().length();
                if (nameMinus!=0){
                    return nameMinus;
                }

                return o1.getBirthday().compareTo(o2.getBirthday());
            }
        });
        System.out.println(list);


    }
}


class Employee{
    private String name;
    private double sal;
    private MyDate birthday;

    public Employee(String name, double sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "\nEmployee{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthday=" + birthday +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getsal() {
        return sal;
    }

    public void setsal(double sal) {
        this.sal = sal;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }
}

class MyDate implements Comparable<MyDate>{
    private int day;
    private int month;
    private int year;

    @Override
    public String toString() {
        return "MyDate{" +
                "day=" + day +
                ", month=" + month +
                ", year=" + year +
                '}';
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public MyDate(int day, int month, int year) {
        this.day = day;
        this.month = month;
        this.year = year;
    }

    @Override
    public int compareTo(@NotNull MyDate o) {
        int yearMinus = this.getYear() - o.getYear();
        if (yearMinus != 0){
            return yearMinus;
        }

        int monthMinus = this.getMonth() - o.getMonth();
        if (monthMinus != 0){
            return monthMinus;
        }

        int dayMinus = this.getDay() - o.getDay();
        if (dayMinus != 0){
            return dayMinus;
        }

        return 0;
    }
}

